package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.pojo.ProcessClassify;
import com.example.mapper.ProcessClassifyMapper;
import com.example.service.IProcessClassifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.vo.ResultVo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 流程分类表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2022-04-10
 */
@Service
public class ProcessClassifyServiceImpl extends ServiceImpl<ProcessClassifyMapper, ProcessClassify> implements IProcessClassifyService {

    @Override
    public ResultVo getProClassify() {
        List<ProcessClassify> processClassifies = baseMapper.selectList(null);
        return ResultVo.response(processClassifies);
    }

    @Override
    public ResultVo getProClassifyOptions() {
        QueryWrapper<ProcessClassify> wrapper = new QueryWrapper<>();
        wrapper.select("name as label,id as value");
        List<Map<String, Object>> maps = baseMapper.selectMaps(wrapper);
        return ResultVo.response(maps);
    }

    @Override
    public Boolean hasSomeNameProClassify(Integer id, String name) {
        QueryWrapper<ProcessClassify> wrapper = new QueryWrapper<>();
        wrapper.eq("name", name)
                .notIn(id!=null,"id",id);
        Long aLong = baseMapper.selectCount(wrapper);
        return aLong > 0;
    }
}
